/*
 * @version: 1.0
 * @Author: zhl
 * @Date: 2022-01-20 11:55:07
 * @LastEditors: zhl
 * @LastEditTime: 2022-01-20 15:11:36
 * @Description: 文件实现描述
 */
#ifndef __CLOUD_EDGE_MANAGER_H__
#define __CLOUD_EDGE_MANAGER_H__

#include <iostream>
#include <memory>

#include "CMosquittoManager.h"
#include "TaskManager.h"
#include "DataCenterManager.h"

class CloudEdgeManager
{
private:
    /* data */
    std::string c_sn;
    std::shared_ptr<TaskManager> c_tm;
    std::shared_ptr<CConfigManager> c_cm;
    
    pthread_t c_conn_thread;
private:
    static int cloud_callback(CALLBACK_TYPE cb_type, void *data, int data_len, int result, void *arg);
    static void *conn_thread(void *arg);
    std::string get_sn();
    
public:
    std::shared_ptr<CMosquittoManager> c_mm;
    std::shared_ptr<CMosquittoManager> c_local_mm;
    std::shared_ptr<DataCenterManager> c_dcm;

    char    c_host[32];
    int     c_port;
    char    c_username[64];
    char    c_password[64];
    int     c_keepalive;
    bool    c_actived;

public:
    CloudEdgeManager(std::shared_ptr<CConfigManager> cm, std::shared_ptr<TaskManager> tm, 
                     std::shared_ptr<CMosquittoManager> mm,std::shared_ptr<DataCenterManager> dcm);
    ~CloudEdgeManager();

    int subscribe_topics();
    int handle_message(void *data, int data_len);
    int connect();

    int connectBroker(const char *host, int port, const char *username, const char *password, int keepalive);
};




#endif /* __CLOUD_EDGE_MANAGER_H__ */